import { ViewWordExpose, ViewWordOptions } from "./types";
import { validateFileType } from "./validate";

type Fn = (...args: any[]) => void;

const listeners = [] as Fn[];


export function pushListener(fn: Fn) {
  listeners.push(fn);
}


export function removeListener(fn: Fn) {
  listeners.splice(listeners.indexOf(fn), 1);
}



export function display(
  url: string,
  options?: ViewWordOptions
) {
  const listener = listeners[0];

  listener(url, options);
}


export const previewDisplay: ViewWordExpose = {
  display,
  validateFileType
};